package red.lsk.business.service.impl;

import java.math.BigDecimal;
import java.util.List;

import cn.hutool.core.util.IdUtil;
import red.lsk.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import red.lsk.business.mapper.BizDiscountConfigMapper;
import red.lsk.business.domain.BizDiscountConfig;
import red.lsk.business.service.IBizDiscountConfigService;
import red.lsk.common.core.text.Convert;
import red.lsk.common.utils.uuid.IdUtils;


/**
 * 充值规则管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-05-09
 */
@Service
public class BizDiscountConfigServiceImpl implements IBizDiscountConfigService 
{
    @Autowired
    private BizDiscountConfigMapper bizDiscountConfigMapper;

    /**
     * 查询充值规则管理
     * 
     * @param id 充值规则管理主键
     * @return 充值规则管理
     */
    @Override
    public BizDiscountConfig selectBizDiscountConfigById(String id)
    {
        return bizDiscountConfigMapper.selectBizDiscountConfigById(id);
    }

    /**
     * 查询充值规则管理列表
     * 
     * @param bizDiscountConfig 充值规则管理
     * @return 充值规则管理
     */
    @Override
    public List<BizDiscountConfig> selectBizDiscountConfigList(BizDiscountConfig bizDiscountConfig)
    {
        return bizDiscountConfigMapper.selectBizDiscountConfigList(bizDiscountConfig);
    }

    /**
     * 新增充值规则管理
     * 
     * @param bizDiscountConfig 充值规则管理
     * @return 结果
     */
    @Override
    public int insertBizDiscountConfig(BizDiscountConfig bizDiscountConfig)
    {
        //生成雪花id 用Hutools
        String idStr = IdUtil.getSnowflake(1, 1).nextIdStr();
        bizDiscountConfig.setId(idStr);
        bizDiscountConfig.setCreateTime(DateUtils.getNowDate());
        return bizDiscountConfigMapper.insertBizDiscountConfig(bizDiscountConfig);
    }

    /**
     * 修改充值规则管理
     * 
     * @param bizDiscountConfig 充值规则管理
     * @return 结果
     */
    @Override
    public int updateBizDiscountConfig(BizDiscountConfig bizDiscountConfig)
    {
        bizDiscountConfig.setUpdateTime(DateUtils.getNowDate());
        return bizDiscountConfigMapper.updateBizDiscountConfig(bizDiscountConfig);
    }

    /**
     * 批量删除充值规则管理
     * 
     * @param ids 需要删除的充值规则管理主键
     * @return 结果
     */
    @Override
    public int deleteBizDiscountConfigByIds(String ids)
    {
        return bizDiscountConfigMapper.deleteBizDiscountConfigByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除充值规则管理信息
     * 
     * @param id 充值规则管理主键
     * @return 结果
     */
    @Override
    public int deleteBizDiscountConfigById(String id)
    {
        return bizDiscountConfigMapper.deleteBizDiscountConfigById(id);
    }
    /**
     * 根据金额查询折扣
     */
    public BigDecimal selectBizDiscountConfigByMoney(BigDecimal money){
        BigDecimal rate = bizDiscountConfigMapper.selectBizDiscountConfigByMoney(money);
        //如果查不到,则赋值为100
        if(rate == null){
            rate = new BigDecimal(100);
        }
        return rate;
    }
}
